package com.ewanghuiju.app.ui.message.adapter;

import android.os.Build;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.local.MessageCommonBean;
import com.ewanghuiju.app.util.TimeUtils;
import com.ewanghuiju.app.widget.FixedAspectRatioFrameLayout;

/**
 * @author sj  qq:751943509
 * @class 消息列表   包含系统消息, 个人消息 ，新手信息
 * @time 2020/2/20
 */
public class MessageListAdapter extends BaseQuickAdapter<MessageCommonBean, BaseViewHolder> {
    public MessageListAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageCommonBean item) {
        try {
//            helper.setText(R.id.tv_text, item.getText());
            TextView tv_title = helper.getView(R.id.tv_title);
            TextView tv_text = helper.getView(R.id.tv_text);
            if (item.getType() == Constants.GEREN_MESSAGE) {
                tv_title.setVisibility(View.GONE);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    tv_text.setText(Html.fromHtml(item.getText(), Html.FROM_HTML_MODE_COMPACT));
                } else {
                    tv_text.setText(Html.fromHtml(item.getText()));
                }
            } else {
                tv_title.setVisibility(View.VISIBLE);
                tv_title.setText(item.getTitle());
                tv_text.setText(item.getVice_title());
            }
            helper.setText(R.id.tv_time, TextUtils.isEmpty(item.getCreate_time())? TimeUtils.getNowString() :item.getCreate_time());
            if (item.getType() == Constants.ACTIVITY_MESSAGE) {
                if (!TextUtils.isEmpty(item.getActivityime())) {
                    helper.setText(R.id.tv_activity_time, item.getActivityime());
                }
                FixedAspectRatioFrameLayout fixFrameLayout = helper.getView(R.id.fix_frameLayout);
                ImageView iv_over = helper.getView(R.id.iv_over);
                ImageView iv_banner = helper.getView(R.id.iv_banner);
                ImageLoader.load(mContext, item.getImg(), iv_banner);
                if (item.getStatus() == 1) {
                    fixFrameLayout.setForeground(mContext.getResources().getDrawable(R.color.transparent_66));
                    iv_over.setVisibility(View.VISIBLE);
                } else {
                    fixFrameLayout.setForeground(mContext.getResources().getDrawable(R.color.transparent));
                    iv_over.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
